//
//  AppUser.swift
//  ExtremeHealth
//
//  Created by Zhongkai Li 李忠凯 on 2018/9/21.
//  Copyright © 2018 GanDongKeJi. All rights reserved.
//

import Foundation

public class AppUser {
    public static let current: AppUser = AppUser()
    private var tokenInfo = TokenInfo(accessToken: "", refreshToken: "")

    public var accessToken: String {
        set {
            tokenInfo.accessToken = accessToken
        }
        get {
            return tokenInfo.accessToken
        }
    }

    public var refreshToken: String {
        set {
            tokenInfo.refreshToken = refreshToken
        }
        get {
            return tokenInfo.refreshToken
        }
    }

    public func setUp() {
        let tokenInfo = AppUserTool.fetch()
        self.tokenInfo = tokenInfo
    }

    public func update(tokenInfo: TokenInfo) {
        AppUserTool.save(tokenInfo)
        self.tokenInfo = tokenInfo
    }
}

public class TokenInfo: Codable {
    public var accessToken: String
    public var refreshToken: String
    public init(accessToken: String, refreshToken: String) {
        self.accessToken = accessToken
        self.refreshToken = refreshToken
    }
}
